import router from './router'
import store from './store'


router.beforeEach(async (to, from, next) => {
  if (!sessionStorage.getItem('userId')&&to.path!=='/login') {
    next('/login')
  }else{
    if (sessionStorage.getItem('userId')&&(store.state.stores.length===0||store.state.region.length===0)) {
      await Promise.all([store.dispatch('GetStores'),store.dispatch('GetRegion')])
    }
    next()
  }
});

router.afterEach((to, from) => {

});
